package com.ellricky.baselib.ui

import android.widget.Toast
import com.andr.common.ui.activity.BaseToolBarActivity
import com.andr.common.ui.mvp.BasePresenter
import com.ellricky.baselib.R
import com.ellricky.baselib.cache.LocalCacheUtil
import com.ellricky.baselib.dialog.picker.EPickerStrListener
import com.ellricky.baselib.dialog.picker.EPickerUtil
import com.ellricky.baselib.http.HttpUtils
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.baselib.util.NewECallback
import kotlinx.android.synthetic.main.base_activity_create_active.*

class CreateActiveActivity : BaseToolBarActivity<Void, BasePresenter<Void>>() {

    private lateinit var ePickerUtil: EPickerUtil

    override fun getContentLayout(): Int {
        return R.layout.base_activity_create_active
    }

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = "创建活动"
        ePickerUtil = EPickerUtil(this)


        etStartTime.setOnClickListener {
            val time = etStartTime.value
            ePickerUtil.showStartDatePicker(time) { content,
                                                    _,
                                                    _ ->
                etStartTime.value = content
            }
        }

        etEndTime.setOnClickListener {
            val time = etEndTime.value
            ePickerUtil.showEndDatePicker(time) { content,
                                                  _,
                                                  _ ->
                etEndTime.value = content
            }
        }

        tv_confirm.setOnClickListener {
            val activeName = etActiveName.value
            val startTime = etStartTime.value
            val endTime = etEndTime.value
            val activeAddress = etActiveAddress.value

            val url = EAppUtil.getApiHost()
            val params = hashMapOf<String, String>()
            params.put("action", "addActivity")
            params.put("activity_name", activeName)
            params.put("activity_address", activeAddress)
            params.put("activity_starttime", startTime)
            params.put("activity_endtime", endTime)
            params.put("eid", LocalCacheUtil.getUid())

            HttpUtils.getInstance().postFrom(url, params, object : NewECallback<Any>(this) {
                override fun onSuccess(data: Any?, msg: String?) {
                    Toast.makeText(this@CreateActiveActivity, "添加成功", Toast.LENGTH_SHORT).show()
                    finish()
                }
            })
        }
    }
}